package org.millioncall.yueyoga.admin.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.millioncall.openplatform.common.PaginateParams;
import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.openplatform.common.StartLimitPairImpl;
import org.millioncall.openplatform.dao.PreparedQuery;
import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.StatusDAO;
import org.millioncall.yueyoga.admin.model.Status;
import org.springframework.stereotype.Repository;

@Repository
public class StatusDAOImpl extends BaseDao implements StatusDAO {

	@Override
	public int deleteByPrimaryKey(Integer id) {
		return 0;
	}

	@Override
	public int insert(Status record) {
		return this.getPagableSqlSessionTemplate().insert("insertStatus",
				record);
	}

	@Override
	public int insertSelective(Status record) {
		return 0;
	}

	@Override
	public Status selectByPrimaryKey(Integer id) {
		return null;
	}

	@Override
	public int updateByPrimaryKeySelective(Status record) {
		return 0;
	}

	@Override
	public int updateByPrimaryKey(Status record) {
		return 0;
	}

	@Override
	public List<Status> findByType(int type) {
		return this.getPagableSqlSessionTemplate().selectList(
				"selectStatusByType", type);
	}

	@Override
	public List<Status> findByParentCode(String code) {
		return this.getPagableSqlSessionTemplate().selectList(
				"selectStatusByParentCode", code);
	}

	@Override
	public Status findByCode(String code) {
		return this.getPagableSqlSessionTemplate().selectOne(
				"selectStatusByCode", code);
	}

	@Override
	public Status findById(int id) {
		return this.getPagableSqlSessionTemplate().selectOne(
				"selectStatusById", id);
	}

	@Override
	public PaginatedList<Status> getStatusInPage(int start, int limit,
			Map<String, Object> map) {
		PreparedQuery<Status> pq = this.getPagableSqlSessionTemplate().findAll(
				"findStatusPage", map);
		PaginatedList<Status> pl = pq.list(new PaginateParams(
				new StartLimitPairImpl(start, limit)));
		return pl;
	}

	@Override
	public void deleteByIds(Integer[] deids) {
		Map<String, Object> map = new HashMap<String, Object>();
		for (int i = 0; i < deids.length; i++) {
			map.put("id", deids[i]);
			this.getPagableSqlSessionTemplate().insert("deleteStatus", map);
		}
	}

	@Override
	public int update(Status status) {
		return this.getPagableSqlSessionTemplate().insert("updateStatus",
				status);
	}

	@Override
	public String findCodeByTypeName(int type, String name) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("name", name);
		return this.getPagableSqlSessionTemplate().selectOne(
				"findCodeByTypeName", map);
	}
}
